﻿// Decompiled with JetBrains decompiler
// Type: 我的小工具.PinyinHelper
// Assembly: 开发辅助工具, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null
// MVID: F78E5980-5E94-4E46-ABDF-DC8C6CBF52AA
// Assembly location: K:\Tools\工具\开发辅助工具庆六一版\开发辅助工具2015-06-01\开发辅助工具.exe

using Microsoft.International.Converters.PinYinConverter;
using System.Collections.Generic;

namespace 我的小工具
{
  public static class PinyinHelper
  {
    public static string GetPinyin(string str)
    {
      string str1 = string.Empty;
      List<string> stringList1 = new List<string>();
      List<string> stringList2 = new List<string>();
      foreach (char ch in str)
      {
        stringList2.Clear();
        try
        {
          foreach (string pinyin in new ChineseChar(ch).Pinyins)
          {
            if (!string.IsNullOrEmpty(pinyin))
            {
              string str2 = pinyin.Substring(0, pinyin.Length - 1);
              if (!stringList2.Contains(str2))
                stringList2.Add(str2);
            }
          }
        }
        catch
        {
          stringList2.Add(ch.ToString());
        }
        stringList1 = PinyinHelper.GetMultiplyList(new List<string>((IEnumerable<string>) stringList1), new List<string>((IEnumerable<string>) stringList2));
      }
      return string.Join(",", stringList1.ToArray());
    }

    public static string GetFirstPinyin(string str)
    {
      string str1 = string.Empty;
      List<string> stringList1 = new List<string>();
      List<string> stringList2 = new List<string>();
      foreach (char ch in str)
      {
        stringList2.Clear();
        try
        {
          foreach (string pinyin in new ChineseChar(ch).Pinyins)
          {
            if (!string.IsNullOrEmpty(pinyin))
            {
              string str2 = pinyin.Substring(0, 1);
              if (!stringList2.Contains(str2))
                stringList2.Add(str2);
            }
          }
        }
        catch
        {
          stringList2.Add(ch.ToString());
        }
        stringList1 = PinyinHelper.GetMultiplyList(new List<string>((IEnumerable<string>) stringList1), new List<string>((IEnumerable<string>) stringList2));
      }
      return string.Join(",", stringList1.ToArray());
    }

    private static List<string> GetMultiplyList(List<string> arr1, List<string> arr2)
    {
      string str1 = string.Empty;
      List<string> stringList = new List<string>();
      if (arr1.Count == 0)
        return arr2;
      if (arr2.Count == 0)
        return arr1;
      foreach (string str2 in arr1)
      {
        foreach (string str3 in arr2)
        {
          if (!stringList.Contains(str2 + str3))
            stringList.Add(str2 + str3);
        }
      }
      return stringList;
    }
  }
}
